﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;

namespace DARE
{
    /// <summary>
    /// This is a Static image that can move and be displayed only for a time.
    /// Usefull for feedbacks!
    /// </summary>
    [AttrTypeDependentSerializable(typeof(CTimedStaticImageData))]
    public class CTimedStaticImage : CStaticImage
    {
        #region fields

        private CStaticWaypoints m_waypoints;

        /// <summary>
        /// Represents the positions of the widget.
        /// This widget will follow the waypoints with a given time and be displayed until the waypoints timer ends.
        /// </summary>
        public CStaticWaypoints Waypoints { get { return m_waypoints; } }

        public override Vector2 Position
        {
            get
            {
                return base.Position;
            }
            set
            {
                base.Position = value;
                m_waypoints.ClearPointList();
                m_waypoints.AddPoint(new Vector3(m_rect.X, m_rect.Y, 0));
            }
        }

        #endregion

        #region ctor

        public CTimedStaticImage(CHUDSystem hud, CWidget parent, string name)
            : base(hud, parent, name)
        {
            m_waypoints = new CStaticWaypoints();
            Size = new Vector2(64, 64);
        }

        #endregion

        #region run

        public override bool Update(GameTime m_gameTime)
        {
            base.Update(m_gameTime);
            if (m_gameTime.TotalGameTime.TotalMilliseconds < m_waypoints.EndTime)
            {
                Vector3 vect = m_waypoints.GetPosition((float)m_gameTime.TotalGameTime.TotalMilliseconds);

                m_rect.X = (int)vect.X;
                m_rect.Y = (int)vect.Y;
            }
            else
                HUD.Detach(this);
            return true;
        }

        #endregion
    }
}
